﻿#region Usings

using System;
using System.Text;
using FluentValidation.Results;
using Yandex.Market.Api.Model;

#endregion

namespace Yandex.Market.Api.Validation
{
    public static class Validator
    {
        /// <summary>
        /// </summary>
        /// <param name = "catalog"></param>
        /// <param name = "validationErrors"></param>
        /// <returns></returns>
        public static bool ValidateYmlCatalog(YmlCatalog catalog, out string validationErrors)
        {
            YmlCatalogValidator catalogValidator = new YmlCatalogValidator();
            ValidationResult results = catalogValidator.Validate(catalog);
            StringBuilder errors = new StringBuilder();
            foreach(ValidationFailure failure in results.Errors)
            {
                errors.AppendLine(String.Format("Property {0} failed validation. Error was: {1} Property value '{2}'",
                                                failure.PropertyName,
                                                failure.ErrorMessage,
                                                failure.AttemptedValue));
            }

            validationErrors = errors.ToString();
            return results.IsValid;
        }
    }
}